/*DrillInfoMaterial  培训资料*/
import request from "/@/utils/request";
import download from "/@/utils/download.ts";

const DrillInfoMaterialApi = {

    getPageData(data: any) {
        return request({
            url: "/drillInfoMaterial/pageData",
            method: "post",
            data,
        });
    },

    getDrillPageData(data: any){
        return request({
            url: "/drillInfo/companyDrillPageData",
            method: "post",
            data
        })
    },

    getDetail(data: any) {
        return request({
            url: "/drillInfoMaterial/getDetail",
            method: "post",
            data,
        });
    },

    save: (data: any) => {
        return request({
            url: "/drillInfoMaterial/save",
            method: "post",
            data,
        });
    },
      downloadAttachment(url: string) {
        // 创建一个 a 标签，模拟点击下载
        const link = document.createElement('a');
        link.href = url;
        link.target = '_blank'; // 在新标签页中打开，避免当前页面跳转
        link.download = url.substring(url.lastIndexOf('/') + 1); // 设置下载的文件名

        document.body.appendChild(link);
        link.click();
        document.body.removeChild(link); // 移除 a 标签
    },
    del: (data: any) => {
        return request({
            url: "/drillInfoMaterial/del",
            method: "post",
            data,
        });
    },

    updateStatus: (data: any) => {
        return request({
            url: "/drillInfoMaterial/updateStatus",
            method: "post",
            data,
        });
    },
    pageDataXls:(_searchParam: any,_xlsTitle: any) => {
const param = new URLSearchParams();
param.append("_searchParam",JSON.stringify(_searchParam))
param.append("_xlsTitle",_xlsTitle)
        return request({
            url: "/drillInfoMaterial/pageDataXls",
            method: "post",
            responseType: 'blob',
            headersType: 'application/json;charset=UTF-8',
           params:param,
        }).then((res)=> {
            download(res)
        });
    },
};
export default DrillInfoMaterialApi;
